<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
       <%
       String name=request.getParameter("name");
       if(name!=null&&!name.trim().equals("")){
    	   Cookie cookie=new Cookie("name",name);
    	   cookie.setMaxAge(10);
    	   response.addCookie(cookie);
       }else{
    	   Cookie[] cookies=request.getCookies();
    	   if(cookies!=null&&cookies.length>0){
    		   for(Cookie c:cookies){
    			   String cookieName=c.getName();
    			   if("name".equals(cookieName)){
    				   name=c.getValue();
    			   }	
    		   }
    	   }   
       }
       if(name!=null&&!name.trim().equals("")){
    	   out.print("hello,"+name);   		   
	   }else{
		   response.sendRedirect("login.jsp");  
	   }
       %>
</body>
</html>